<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@page import="com.utility.*,com.bean.*" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Mobile Shop</title>
</head>
<body>

<%! MobileDAO mobileDAO = new MobileDAO(); ArrayList<Mobile> mobilesList; %>

<%
	String name = request.getParameter("name").trim();
	if (name == null || name.equals(""))
	{
		out.println("<font size='4' color='red' > Please Enter Some Name!!! </font>");
	}
	else
	{
		if (!name.matches("[a-zA-Z0-9 %]+"))
		{
			out.println("<font size='4' color='red' > Wrong Name </font> <br />");
			out.println("<a href='javascript:history.back()'> Back </a>");
			return;
		}
		mobilesList = mobileDAO.get(name);
		
		if (mobilesList.isEmpty())
			out.println("<font size='4' color='red' > No Record Found for the name : " + name + " </font>");
		else
		{
%>
		<h2>  Mobile Records  </h2> <hr />
		<table border="1" align="center">
		<TR>
		<th> ID </th> 
		<th> Model Name </th> 
		<th> Company </th> 
		<th> Camera </th> 
		<th> Price </th> 
		</TR>
		
		<% for(Mobile mobile : mobilesList) 
		{ 
			out.print("<TR>");
			out.print("<td>" + mobile.getId() + "</td>");
			out.print("<td>" + mobile.getModel() + "</td>");
			out.print("<td>" + mobile.getCompany() + "</td>");
			out.print("<td>" + mobile.getCamera() + "</td>");
			out.print("<td>" + mobile.getPrice() + "</td>");
			out.print("</TR>");
		} 
		%>
		
		</table>
		
	<% } } %>
	<hr />
	<a href="javascript:history.back()"> Back </a>

</body>
</html>